package com.xmx.usercenter.service.impl;

import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xmx.common.utils.PageUtils;
import com.xmx.common.utils.Query;

import com.xmx.usercenter.dao.AddressDao;
import com.xmx.usercenter.entity.AddressEntity;
import com.xmx.usercenter.service.AddressService;

import javax.annotation.Resource;


@Service("addressService")
public class AddressServiceImpl extends ServiceImpl<AddressDao, AddressEntity> implements AddressService {

    @Resource
    AddressDao addressDao;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<AddressEntity> page = this.page(
                new Query<AddressEntity>().getPage(params),
                new QueryWrapper<AddressEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public AddressEntity findlistByuid(Integer uid,Integer addressId) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("id",addressId);
        queryWrapper.eq("user_id",uid);
        return addressDao.selectOne(queryWrapper);
    }

    @Override
    public AddressEntity findlistByDefault(Integer uid) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("user_id",uid);
        queryWrapper.eq("is_default",1);
        return addressDao.selectOne(queryWrapper);
    }

}